package lab03.test05;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test05 {
    public static void main(String[] args) {

        String path="E:\\test.txt";
        FileOutputStream fileOutputStream=null;
        FileInputStream fileInputStream=null;

        try {

            fileOutputStream=new FileOutputStream(path);
            fileInputStream=new FileInputStream(path);
            String str="hello";
            byte[] byteArray = str.getBytes();//将string转化为byte数组

            //加密算法
            for (int i=0;i<byteArray.length;i++){

                byteArray[i]+=1;
            }
            fileOutputStream.write(byteArray);//写文件

            //读文件  解密
            int current;
            while ((current=fileInputStream.read())!=-1) {
                System.out.print((char)(current-1));
            }


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {

            try {
                fileInputStream.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
